package chapter04.sync;

import java.util.concurrent.locks.LockSupport;

public class ABCTest4 {
    static Thread t1;
    static Thread t2;
    static Thread t3;
    public static void main(String[] args) {
        PackUnPack packUnPack = new PackUnPack(5);
         t1 = new Thread(() -> {
            packUnPack.print("a", t2);
        }, "t1");

         t2 = new Thread(() -> {
            packUnPack.print("b", t3);
        }, "t2");
         t3 = new Thread(() -> {
            packUnPack.print("c", t1);
        }, "t3");
         t1.start();
         t2.start();
         t3.start();
        LockSupport.unpark(t1);
    }
}
class PackUnPack{
    private int loopnumber;

    public PackUnPack(int loopnumber) {
        this.loopnumber = loopnumber;
    }

    public void print(String str,Thread next){
        for(int i=1;i<=loopnumber;i++){
            LockSupport.park();
            System.out.print(str);
            LockSupport.unpark(next);
        }
    }
}
